﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using League.Entity;
using HtmlAgilityPack;
using JJY.CommonHelper;

namespace League.Business
{
    public class MatchDataOrganizeMonitorForReportPage
    {
        private const string dataTableClass = "daTb03";

        private LeagueTeamData homeTeam = new LeagueTeamData();
        private LeagueTeamData visitingTeam = new LeagueTeamData();
        private LeagueInfo leagueInfo = new LeagueInfo();

        public LeagueTeamData _HomeTeam 
        {
            get { return homeTeam; } 
        }

        public LeagueTeamData _VisitingTeam 
        {
            get { return visitingTeam; } 
        }

        public LeagueInfo _LeagueInfo 
        {
            get { return leagueInfo; } 
        }

        /*
        public MatchDataOrganizeMonitorForReportPage(string strUrl)
        {
            
            //strUrl = "http://goal.sports.163.com/22/match/report/2010/330243.html";

            string strHtml = HttpRequestService.GetHtmlSourceByUrl(strUrl, Encoding.UTF8)
                .Replace(@"\t", "").Replace(@"\r", "").Replace(@"\n", "")
                .Replace("&nbsp;", "").Replace("　", "").Trim();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(strHtml);


            HtmlNode nodeTableMatch = doc.DocumentNode.SelectNodes(string.Format("//table[@class='{0}']", dataTableClass))[0];
            HtmlNode nodeTableRanking = doc.DocumentNode.SelectNodes(string.Format("//table[@class='{0}']", dataTableClass))[1];

            HtmlNodeCollection nodeTableMatchTR = doc.DocumentNode.SelectNodes(nodeTableMatch.XPath + "/tr");
            HtmlNodeCollection nodeRankingTR = doc.DocumentNode.SelectNodes(nodeTableRanking.XPath + "/tr");


            //get first tr which child node is th, and include team name
            HtmlNodeCollection nodeTDSet = doc.DocumentNode.SelectNodes(nodeTableMatchTR[0].XPath + "/th");
            homeTeam.TeamName = nodeTDSet[0].InnerText.Replace(" ", string.Empty);
            visitingTeam.TeamName = nodeTDSet[2].InnerText.Replace(" ", string.Empty);

            for (int i = 1; i < nodeTableMatchTR.Count; i++)
            {
                nodeTDSet = doc.DocumentNode.SelectNodes(nodeTableMatchTR[i].XPath + "/td");

                if (nodeTDSet.Count == 3)
                {
                    string valueA = nodeTDSet[0].InnerText.Replace("%", string.Empty).Replace(" ", string.Empty);
                    string valueB = nodeTDSet[2].InnerText.Replace("%", string.Empty).Replace(" ", string.Empty);
                    switch (i)
                    {
                        #region collecte team data
                        case 1:
                            homeTeam.Goal = byte.Parse(valueA);
                            visitingTeam.Goal = byte.Parse(valueB);
                            break;
                        case 2:
                            homeTeam.Shot = byte.Parse(valueA);
                            visitingTeam.Shot = byte.Parse(valueB);
                            break;
                        case 3:
                            homeTeam.ShotOnTarget = byte.Parse(valueA);
                            visitingTeam.ShotOnTarget = byte.Parse(valueB);
                            break;
                        case 4:
                            homeTeam.ShotOutTarget = byte.Parse(valueA);
                            visitingTeam.ShotOutTarget = byte.Parse(valueB);
                            break;
                        case 5:
                            homeTeam.BlockedShot = byte.Parse(valueA);
                            visitingTeam.BlockedShot = byte.Parse(valueB);
                            break;
                        case 6:
                            homeTeam.Corner = byte.Parse(valueA);
                            visitingTeam.Corner = byte.Parse(valueB);
                            break;
                        case 7:
                            homeTeam.FreeKick = byte.Parse(valueA);
                            visitingTeam.FreeKick = byte.Parse(valueB);
                            break;
                        case 8:
                            homeTeam.OutOfBounds = byte.Parse(valueA);
                            visitingTeam.OutOfBounds = byte.Parse(valueB);
                            break;
                        case 9:
                            homeTeam.Foul = byte.Parse(valueA);
                            visitingTeam.Foul = byte.Parse(valueB);
                            break;
                        case 10:
                            homeTeam.Offside = byte.Parse(valueA);
                            visitingTeam.Offside = byte.Parse(valueB);
                            break;
                        case 11:
                            homeTeam.DivingSave = byte.Parse(valueA);
                            visitingTeam.DivingSave = byte.Parse(valueB);
                            break;
                        case 12:
                            homeTeam.Trackling = byte.Parse(valueA);
                            visitingTeam.Trackling = byte.Parse(valueB);
                            break;
                        case 13:
                            homeTeam.YellowCard = byte.Parse(valueA);
                            visitingTeam.YellowCard = byte.Parse(valueB);
                            break;
                        case 14:
                            homeTeam.RedCard = byte.Parse(valueA);
                            visitingTeam.RedCard = byte.Parse(valueB);
                            break;
                        case 15:
                            homeTeam.BallControl = decimal.Parse(valueA);
                            visitingTeam.BallControl = decimal.Parse(valueB);
                            break;
                        case 16:
                            homeTeam.PassSuccess = decimal.Parse(valueA);
                            visitingTeam.PassSuccess = decimal.Parse(valueB);
                            break;
                        case 17:
                            homeTeam.PassMiddleSuccess = decimal.Parse(valueA);
                            visitingTeam.PassMiddleSuccess = decimal.Parse(valueB);
                            break;
                        case 18:
                            homeTeam.TracklingSuccess = decimal.Parse(valueA);
                            visitingTeam.TracklingSuccess = decimal.Parse(valueB);
                            break;
                        case 19:
                            homeTeam.HeadSuccess = decimal.Parse(valueA);
                            visitingTeam.HeadSuccess = decimal.Parse(valueB);
                            break;
                        #endregion
                    }
                }
            }            
        }*/
    }
}
